package com.hcy.rabbitmanagerapi.utils;

import com.hcy.rabbitbasicmodel.enums.Clients;
import com.hcy.rabbitbasicmodel.enums.Log_Code;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.userclient.client.UserAuthClient;
import com.hcy.usermodel.dto.request.AddLogRequestDTO;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author huchenying
 * @Description 上传日志
 * @Date 2022/4/21 21:41
 */
@Slf4j
public class AutoLogUpload implements Runnable {

    private final UserAuthClient userAuthClient;
    private final Log_Code log_code;
    private final String username;
    private final String remark;

    public AutoLogUpload(UserAuthClient userAuthClient, Log_Code log_code,String username,String remark){
        this.userAuthClient = userAuthClient;
        this.log_code = log_code;
        this.username = username;
        this.remark = remark;
    }

    /**
     * @Author huchenying
     * @Description  调用user 上传操作日志
     * @Date 2022/4/21 21:45
     **/
    @Override
    public void run() {
        AddLogRequestDTO addLogRequestDTO = new AddLogRequestDTO();
        addLogRequestDTO.setOperateType(log_code.getType());
        addLogRequestDTO.setRemark(remark);
        addLogRequestDTO.setUserName(username);
        addLogRequestDTO.setBusinessCode(Clients.MANAGER.getName());
        ResponseData<Object> responseData = userAuthClient.addOptLog(addLogRequestDTO);
        if(responseData.getCode().isSuccess()){
            log.info("操作记录上传成功");
        }
    }
}
